package direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import util.ConnectionRabbitMQ;

/**
 * 消息生产者
 */
public class Sender {
    public static void main(String[] args) throws Exception {

        // 1.获得连接
        Connection connection = ConnectionRabbitMQ.getConnection();
        // 2.在连接中创建通道
        Channel channel = connection.createChannel();
        // 声明路由(路由名，路由类型)
        // direct:根据路由键定向分发消息
        channel.exchangeDeclare("test_exchange_direct","direct");
        String msg = "用户注册,[userId=S101]";
        // 3.创建消息队列(1,2,3,4,5)
        //channel.queueDeclare("queue1",false,false,false,null);
        // 4.向指定的队列发送消息(1,2,3,4)
        channel.basicPublish("test_exchange_direct","insert",null,msg.getBytes());
        System.out.println("[用户系统]:"+msg);
        // 5.释放资源
        channel.close();
        connection.close();
    }
}
